package com.lin.cloud.disk.controller;

import com.lin.cloud.disk.entity.request.*;
import com.lin.cloud.disk.entity.response.UserInfoByTokenResponse;
import com.lin.cloud.disk.entity.response.UserInfoResponse;
import com.lin.cloud.disk.manage.IUserManageService;
import com.lin.cloud.disk.service.IUserService;
import com.lin.cloud.disk.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author ljc
 * @since 2020-12-10 16:48:58
 */
@RestController
@RequestMapping("/api/user")
@Slf4j
@Api(tags = "用户控制器")
public class UserController {

    @Resource
    private IUserService userService;

    @Resource
    private IUserManageService userManageService;


    /**
     * 通过token获取用户信息
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "通过token获取用户信息", response = UserInfoByTokenResponse.class)
    @PostMapping("/info")
    public Result<UserInfoByTokenResponse> getByToken(@RequestBody @Validated JwtTokenRequest request) {
        UserInfoByTokenResponse response = userManageService.getUserInfoByToken(request);
        return Result.success(response);
    }


    @ApiOperation(value = "修改密码")
    @PutMapping("/modifyPassword")
    public Result modifyPassword(@RequestBody @Validated ModifyPasswordRequest request) {
        userManageService.modifyPassword(request);
        return Result.success();
    }

    @ApiOperation(value = "修改个人信息")
    @PutMapping("/modifyUserInfo")
    public Result modifyUserInfo(@RequestBody @Validated ModifyUserInfoRequest request) {
        userService.modifyUserInfo(request);
        return Result.success();
    }


    @ApiOperation(value = "获取用户详情列表")
    @PostMapping("/getUserInfoList")
    public Result<List<UserInfoResponse>> getUserInfoList(@RequestBody @Validated GetUserInfoListRequest request) {
        return Result.success(userService.getUserInfoList(request));
    }

    @ApiOperation(value = "通过ID列表删除用户")
    @DeleteMapping("/deleteUserByIdList")
    public Result deleteUserByIdList(@RequestBody @Validated DeleteUserByIdListRequest request){
        userService.deleteUserByIdList(request);
        return Result.success();
    }




}